package dipl.algorithm.math.primitive.op;

import dipl.algorithm.math.utility.FPMath;
import org.apfloat.Apfloat;

/**
 * operations in complex number space
 */
public class ComplexOps {

	//
	// PUBLIC METHODS
	//

	/**
	 * calculates argument (in radians) of given complex number.
	 * The resulting angle lies in [0,2*PI]
	 * @param fpMath
	 * @param r
	 * @param i
	 * @return
	 */
	public static Apfloat Argument( FPMath fpMath, Apfloat r, Apfloat i ) {
		Apfloat angle = null;
		try {
			angle = fpMath.m.atan2( i, r );
		}
		catch( Exception e ) {
			return Apfloat.ZERO;
		}
		if( angle.compareTo( Apfloat.ZERO ) < 0 )
			return fpMath.m.add( angle, fpMath._2PI );
		return angle;
	}
}
